import type { BasicColumn, FormSchema } from '@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { rules } from '/@/utils/helper/validator';
import { JVxeColumn, JVxeTypes } from '/@/components/jeecg/JVxeTable/types';
import { ref } from 'vue';

export const searchFormSchema: FormSchema[] = [
  {
    label: '属性组名称',
    field: 'name',
    colProps: {
      span: 8,
    },
    component: 'Input',
  },
];

export const columns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'name',
    align: 'center',
  },
  {
    title: '规格值',
    dataIndex: 'valueStr',
    align: 'center',
  },
  {
    title: '备注',
    dataIndex: 'remark',
    align: 'center',
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    align: 'center',
    customRender: render.renderDate,
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '编号',
    field: 'id',
    show: false,
    component: 'Input',
  },
  {
    label: '名称',
    field: 'name',
    required:true,
    component: 'Input',
    dynamicRules:({ model, schema }) => rules.duplicateCheckRule('product_multi_spec', 'name', model, schema, true),
  },
  {
    label: '规格',
    field: 'specs',
    colProps: {
      span: 24,
    },
    component: 'Input',
    slot: 'specIdsSlot',
  },
  {
    label: '备注',
    field: 'remark',
    colProps: {
      span: 24,
    },
    component: 'InputTextArea',
  },
];

export const specIdsSchema = ref<JVxeColumn[]>([
  {
    title: 'id',
    key: 'id',
    align: 'center',
    type: 'hidden',
  },
  {
    title: '规格名',
    key: 'name',
    width:'20%',
    align: 'center',
    type: 'input',
  },
  {
    title: '规格值',
    key: 'valueStr',
    placeholder:'多个规格值以逗号分隔',
    width:'60%',
    align: 'center',
    type: 'textarea',
  },
  {
    title: '操作',
    key: 'action',
    type: JVxeTypes.slot,
    //fixed: 'right',
    width: '10%',
    align: 'center',
    slotName: 'tableAction',
  },
]);
